package org.example;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class ManyToOneExample {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(Util.PERSISTENCE_UNIT);
        EntityManager em = emf.createEntityManager();
        ManyToOneB manyToOneB = new ManyToOneB();
        manyToOneB.setStr("testManyToOneB");

        ManyToOneA manyToOneA = new ManyToOneA();
        manyToOneA.setManyToOneB(manyToOneB);

        ManyToOneA manyToOneA1 = new ManyToOneA();
        manyToOneA1.setManyToOneB(manyToOneB);

        em.getTransaction().begin();
        em.persist(manyToOneA);
        em.persist(manyToOneA1);
        em.persist(manyToOneB);
        em.getTransaction().commit();
        em.close();
    }
}
